import { Global } from '../Global';
import { Fight } from './def/Fight';
import { Entity } from './def/Entity';
import { State } from './def/State';
import {FightFrame} from "db://assets/Script/Fight/FightFrame";

export class MonsterEntity extends Entity {

    fight: Fight = null

    constructor(index: number[], type: string, fight: Fight) {
        super(index, type)
        this.fight = fight
    }

    handleEvent(dirct?: string) {
        Global.heroManage.globalMoveKey = true
        Global.fightManage.fight(this, Global.hero, (success: boolean, frame? : FightFrame) => {
            if (!success) {
                Global.popUtil.popUp('你还无法战胜它')
                Global.heroManage.globalMoveKey = false
            } else {
                Global.popUtil.popUp(`战斗胜利,增加经验:${this.fight.exper},金币:${this.fight.money}`)

                Global.hero._heroState.fight.life = frame.hBlood
                Global.hero.addExper(this.fight.exper)
                Global.hero._heroState.state.money += this.fight.money
                Global.em.removeEntity(Global.fm.getFloor(), this)
                Global.heroManage.globalMoveKey = false
                switch (dirct) {
                    case ('up'): {
                        Global.heroManage.up()
                        break
                    }
                    case ('down'): {
                        Global.heroManage.down()
                        break
                    }
                    case ('left'): {
                        Global.heroManage.left()
                        break
                    }
                    case ('right'): {
                        Global.heroManage.right()
                        break
                    }
                }
            }
        })
        return {
            move: false,
            cartoon: false
        }
    }

}

